package com.winit.schedule.core.protocol;

import java.util.HashMap;
import java.util.Map;

import com.winit.schedule.core.utils.Clock;
import com.winit.schedule.remoting.CommandBody;
import com.winit.schedule.remoting.annotation.NotNull;
import com.winit.schedule.remoting.annotation.Nullable;
import com.winit.schedule.remoting.exception.RemotingCommandFieldCheckException;

/**
 * 抽象header
 * 
 * @author jianke.zhang 2015-3-17 上午10:58:25
 * @since 1.0
 */
public abstract class AbstractCommandBody implements CommandBody {

    /**
     * 当前节点的唯一标识
     */
    @NotNull
    private String              identity;

    /**
     * 当前时间
     */
    private Long                timestamp = Clock.getSystemTime();

    /**
     * 可用的线程数 (对 TaskTracker才有作用)
     */
    private Integer             availableThreads;

    /**
     * 扩展 参数
     */
    @Nullable
    private Map<String, Object> extParams;

    public AbstractCommandBody(){

    }

    public AbstractCommandBody(String identity){
        this.identity = identity;
    }

    public AbstractCommandBody(String identity, Integer availableThreads){
        this.identity = identity;
        this.availableThreads = availableThreads;
    }

    public void putExtParam(String key, Object obj) {
        if (this.extParams == null) {
            this.extParams = new HashMap<String, Object>();
        }
        this.extParams.put(key, obj);
    }

    public String getIdentity() {
        return identity;
    }

    public void setIdentity(String identity) {
        this.identity = identity;
    }

    public Integer getAvailableThreads() {
        return availableThreads;
    }

    public void setAvailableThreads(Integer availableThreads) {
        this.availableThreads = availableThreads;
    }

    public Long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Long timestamp) {
        this.timestamp = timestamp;
    }

    public Map<String, Object> getExtParams() {
        return extParams;
    }

    public void setExtParams(Map<String, Object> extParams) {
        this.extParams = extParams;
    }

    @Override
    public void checkFields() throws RemotingCommandFieldCheckException {
    }

}
